home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
lang
/
PPCcforth.lha
/
PPCcforth
/
forth.dict
< prev
next >
Wrap
Text File
|
1985-12-27
|
18KB
|
1,043 lines
PRIM EXECUTE 0 ( cfa -- <execute word> )
PRIM LIT 1 ( push the next value to the stack )
PRIM BRANCH 2 ( branch by offset in next word )
PRIM 0BRANCH 3 ( branch if zero by off. in next word )
PRIM (LOOP) 4 ( end of a <DO> )
PRIM (+LOOP) 5 ( inc -- <end of a <DO> w/increment != 1 )
PRIM (DO) 6 ( limit init -- <begin a DO loop> )
PRIM I 7 ( get loop index <R> )
PRIM DIGIT 8 ( c -- DIGIT 1 | 0 <convert digit> )
PRIM (FIND) 9 ( s -- s 0 | s NFA 1 <find word s> )
PRIM ENCLOSE 10 ( addr c -- addr next first last <not quite> )
PRIM KEY 11 ( -- c <get next char from input> )
PRIM (EMIT) 12 ( c -- <put char to output> )
PRIM ?TERMINAL 13 ( see if op. interrupted <like w/^C> )
PRIM CMOVE 14 ( src dest count -- <move words>)
PRIM U* 15 ( unsigned multiply )
PRIM U/ 16 ( unsigned divide )
PRIM AND 17 ( a b -- a&b )
PRIM OR 18 ( a b -- a|b )
PRIM XOR 19 ( a b -- a%b )
PRIM SP@ 20 ( -- sp )
PRIM SP! 21 ( -- <store empty value to sp> )
PRIM RP@ 22 ( -- rp )
PRIM RP! 23 ( -- <store empty value to rp> )
PRIM ;S 24 ( -- <pop r stack <end colon def'n>> )
PRIM LEAVE 25 ( -- <set index = limit for a loop> )
PRIM >R 26 ( a -- <push a to r stack> )
PRIM R> 27 ( -- a <pop a from r stack )
PRIM 0= 28 ( a -- !a <logical not> )
PRIM 0< 29 ( a -- a<0 )
PRIM + 30 ( a b -- a+b )
PRIM D+ 31 ( ahi alo bhi blo -- a+bhi a+blo )
PRIM MINUS 32 ( a -- -a )
PRIM DMINUS 33 ( ahi alo -- <-a>hi <-a>lo )
PRIM OVER 34 ( a b -- a b a )
PRIM DROP 35 ( a -- )
PRIM SWAP 36 ( a b -- b a )
PRIM DUP 37 ( a -- a a )
PRIM 2DUP 38 ( a b -- a b a b )
PRIM +! 39 ( val addr -- < *addr += val > )
PRIM TOGGLE 40 ( addr mask -- <*addr %= mask> )
PRIM @ 41 ( addr -- *addr )
PRIM C@ 42 ( addr -- *addr )
PRIM 2@ 43 ( addr -- *addr+1 *addr )
PRIM ! 44 ( val addr -- <*addr = val> )
PRIM C! 45 ( val addr -- <*addr = val> )
PRIM 2! 46 ( bhi blo addr -- <*addr=blo, *addr+1=bhi )
PRIM DOCOL 47 ( goes into CF of : definitions )
PRIM DOCON 48 ( goes into CF of constants )
PRIM DOVAR 49 ( goes into CF of variables )
PRIM DOUSE 50 ( goes into CF of user variables )
PRIM - 51 ( a b -- a-b )
PRIM = 52 ( a b -- a==b)
PRIM != 53 ( a b -- a!=b)
PRIM < 54 ( a b -- a<b )
PRIM ROT 55 ( a b c -- c a b )
PRIM DODOES 56 ( place holder; this value goes into CF )
PRIM DOVOC 57
PRIM R 58 ( same as I, but must be a primitive )
PRIM ALLOT 59 ( primitive because of mem. management )
PRIM (BYE) 60 ( executes exit <pop[]>; )
PRIM TRON 61 ( depth -- trace to this depth )
PRIM TROFF 62 ( stop tracing )
PRIM DOTRACE 63 ( trace once )
PRIM (R/W) 64 ( BUFFER FLAG ADDR -- read if flag=1, write/0 )
PRIM (SAVE) 65 ( Save current environment )
PRIM (COLD) 66
( end of primitives )
CONST 0 0
CONST 1 1
CONST 2 2
CONST 3 3
CONST -1 -1
CONST BL 32 ( A SPACE, OR BLANK )
CONST C/L 64
CONST B/BUF 1024
CONST B/SCR 1
CONST #BUFF 5 ( IMPLEMENTATION DEPENDENT )
CONST WORDSIZE 1 ( EXTENSION: WORDSIZE IS THE NUMBER OF BYTES IN A WORD.
USUALLY, THIS IS TWO, BUT WITH PSEUDO-MEMORY
ADDRESSED AS AN ARRAY OF WORDS, IT'S ONE. )
CONST FIRST 0 ( ADDRESS OF THE FIRST BUFFER AND END OF BUFFER SPACE )
CONST LIMIT 0 ( the reader fills these in with INITR0 and DPBASE )
USER S0 24
USER R0 25
USER TIB 26
USER WIDTH 27
USER WARNING 28
USER FENCE 29
USER DP 30
USER VOC-LINK 31
USER BLK 32
USER IN 33
USER ERRBLK 34
USER ERRIN 35
USER OUT 36
USER SCR 37
USER OFFSET 38
USER CONTEXT 39
USER CURRENT 40
USER STATE 41
USER BASE 42
USER DPL 43
USER FLD 44
USER CSP 45
USER R# 46
USER HLD 47
VAR USE 0 ( These two are filled in by COLD )
VAR PREV 0 ( to the same as the constant FIRST )
CONST SEC/BLK 1
: EMIT
(EMIT)
1 OUT +! ;
: CR
LIT 13 EMIT
LIT 10 EMIT
0 OUT ! ;
: NOP ; ( DO-NOTHING )
: +ORIGIN ; ( ADD ORIGIN OF SYSTEM; IN THIS CASE, 0 )
: 1+
1 + ;
: 2+
2 + ;
: 1-
1 - ;
: ++ ( ADDR -- <INCREMENTS VAL AT ADDR> )
1 SWAP +! ; ( MY OWN EXTENSION )
: -- ( ADDR -- <DECREMENTS VAL AT ADDR> )
-1 SWAP +! ; ( MY OWN EXTENSION )
: HERE ( -- DP )
DP @ ;
: , ( V -- <PLACES V AT DP AND INCREMENTS DP>)
HERE !
WORDSIZE ALLOT ; ( CHANGE FROM MODEL FOR WORDSIZE )
: C, ( C -- <COMPILE A CHARACTER. SAME AS , WHEN WORDSIZE=1> )
HERE C!
1 ALLOT ;
: U< ( THIS IS TRICKY. )
2DUP XOR 0< ( SIGNS DIFFERENT? )
0BRANCH U1 ( NO: GO TO U1 )
DROP 0< 0= ( YES; ANSWER IS [SECOND > 0] )
BRANCH U2 ( SKIP TO U2 <END OF WORD> )
LABEL U1
- 0< ( SIGNS ARE THE SAME. JUST SUBTRACT
AND TEST NORMALLY )
LABEL U2
;
: > ( CHEAP TRICK )
SWAP < ;
: <> ( NOT-EQUAL )
!= ;
: SPACE ( EMIT A SPACE )
BL EMIT
;
: -DUP ( V -- V | V V <DUPLICATE IF V != 0> )
DUP
0BRANCH DDUP1 ( SKIP TO END IF IT WAS ZERO )
DUP
LABEL DDUP1
;
: TRAVERSE ( A DIR -- A <TRAVERSE A WORD FROM NFA TO LFA
<DIR = 1> OR LFA TO NFA <DIR = -1> )
SWAP
LABEL T1
OVER ( BEGIN )
+
LIT 0x7F OVER C@ < ( HIGH BIT CLEAR? )
0BRANCH T1 ( UNTIL )
SWAP DROP ;
: LATEST ( NFA OF LAST WORD DEFINED )
CURRENT @ @ ;
: LFA ( GO FROM PFA TO LFA )
2 - ; ( 2 IS WORDSIZE*2 )
: CFA ( GO FROM PFA TO CFA )
WORDSIZE - ;
: NFA ( GO FROM PFA TO NFA )
3 - ( NOW AT LAST CHAR )
-1 TRAVERSE ; ( 3 IS WORDSIZE*3 )
: PFA ( GO FROM NFA TO PFA )
1 TRAVERSE ( NOW AT LAST CHAR )
3 + ; ( 3 IS WORDSIZE*3 )
: !CSP ( SAVE CSP AT USER VAR CSP )
SP@ CSP ! ;
: (ABORT)
ABORT
;
: ERROR ( N -- <ISSUE ERROR #N> )
WARNING @ 0< ( WARNING < 0 MEANS <ABORT> )
0BRANCH E1
(ABORT) ( IF )
LABEL E1
HERE COUNT TYPE (.") "?" ( THEN )
MESSAGE
SP! ( EMPTY THE STACK )
BLK @ -DUP ( IF LOADING, STORE IN & BLK )
0BRANCH E2
ERRBLK ! IN @ ERRIN ! ( IF )
LABEL E2
QUIT ( THEN )
;
: ?ERROR ( F N -- <IF F, DO ERROR #N> )
SWAP
0BRANCH QERR1
ERROR ( IF <YOU CAN'T RETURN FROM ERROR> )
LABEL QERR1
DROP ( THEN )
;
: ?COMP ( GIVE ERR#17 IF NOT COMPILING )
STATE @ 0= LIT 17 ?ERROR
;
: ?EXEC ( GIVE ERR#18 IF NOT EXECUTING )
STATE @ LIT 18 ?ERROR
;
: ?PAIRS ( GIVE ERR#19 IF PAIRS DON'T MATCH )
- LIT 19 ?ERROR
;
: ?CSP ( GIVE ERR#20 IF CSP & SP DON'T MATCH )
SP@ CSP @ - LIT 20 ?ERROR
;
: ?LOADING ( GIVE ERR#21 IF NOT LOADING )
BLK @ 0= LIT 22 ?ERROR
;
: COMPILE ( COMPILE THE CFA OF THE NEXT WORD TO DICT )
?COMP
R> DUP ( GET OUR RETURN ADDRESS )
WORDSIZE + >R ( SKIP NEXT; ORIG. ADDR STILL ON TOS )
@ ,
;
: [ ( BEGIN EXECUTING )
0 STATE !
;*
: ] ( END EXECUTING )
LIT 0xC0 STATE !
;*
: SMUDGE ( TOGGLE COMPLETION BIT OF LATEST WORD )
LATEST ( WHEN THIS BIT=1, WORD CAN'T BE FOUND )
LIT 0x20 TOGGLE
;
: :
( DEFINE A WORD )
?EXEC
!CSP
CURRENT @ CONTEXT !
CREATE ] ( MAKE THE WORD HEADER AND BEGIN COMPILING )
(;CODE) DOCOL
;*
: ; ( END A DEFINITION )
?CSP ( CHECK THAT WE'RE DONE )
COMPILE ;S ( PLACE ;S AT THE END )
SMUDGE [ ( MAKE THE WORD FINDABLE AND BEGIN INTERPRETING )
;*
: CONSTANT
CREATE SMUDGE ,
(;CODE) DOCON
;
: VARIABLE
CONSTANT
(;CODE) DOVAR
;
: USER
CONSTANT
(;CODE) DOUSE
;
: HEX ( GO TO HEXADECIMAL BASE )
LIT 0x10 BASE ! ;
: DECIMAL ( GO TO DECIMAL BASE )
LIT 0x0A BASE !
;
: ;CODE ( unused without an assembler )
?CSP COMPILE (;CODE) [ NOP ( "ASSEMBLER" might go where nop is )
;*
: (;CODE) ( differs from the normal def'n )
R> @ @ LATEST PFA CFA !
;
: <BUILDS ( UNSURE )
0 CONSTANT ; ( NOTE CONSTANT != CONST )
: DOES> ( UNSURE )
R> LATEST PFA !
(;CODE) DODOES
;
: COUNT ( ADDR -- ADDR+1 COUNT )
DUP 1+ SWAP C@ ; ( CONVERTS THE <STRING> ADDR TO A FORM SUITABLE
FOR "TYPE" )
: TYPE
-DUP
0BRANCH TYPE1
OVER + SWAP ( GET START .. END ADDRS )
(DO)
LABEL TYPE2
I C@ EMIT
(LOOP) TYPE2
BRANCH TYPE3
LABEL TYPE1
DROP
LABEL TYPE3
;
: -TRAILING ( addr count -- addr count <count adjusted to
exclude trailing blanks> )
DUP 0 (DO) ( DO )
LABEL TRAIL1
OVER OVER + 1 - C@ BL -
0BRANCH TRAIL2
LEAVE BRANCH TRAIL3 ( IF )
LABEL TRAIL2
1 - ( ELSE )
LABEL TRAIL3
(LOOP) TRAIL1 ( THEN LOOP )
;
: (.") ( PRINT A COMPILED STRING )
R COUNT
DUP 1+ R> + >R TYPE
;
: ." ( COMPILE A STRING IF COMPILING,
OR PRINT A STRING IF INTERPRETING )
LIT '"'
STATE @
0BRANCH QUOTE1
COMPILE (.") WORD HE